package com.xiantm.study.thread.threadpermessage;

public class MagicMethod1 {
    public static void main(String[] args) {
        System.out.println("Main Start");
        enter(new Object());
        System.out.println("Main End");
    }

    public static void enter(Object obj){
        System.out.println("Step 1.");
        magic(obj);
        System.out.println("Step 2.");
        synchronized (obj) {
            System.out.println("Step 3.");
        }
    }
    public static void magic(final Object obj){
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj){
                    for(;;);
                }
            }
        }).start();
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
